#!/usr/bin/env python
# @FileName :密码复杂度.py
# @Time :2024/4/8 15:38
# @Author :邹强

def passwd_length():
    global passwd
    if len(passwd) <= 8:
        # print("密码长度不符合要求，没有超过8位")
        return 0
    return 1

def passwd_type():
    global passwd
    big_char, small_char,digit_char, other_char = 0, 0, 0, 0
    for char in passwd:
        if char.isupper():
            big_char = 1
        elif char.islower():
            small_char = 1
        elif char.isdigit():
            digit_char = 1
        else:
            other_char = 1
    if big_char + small_char + digit_char + other_char >= 3:
        return 1
    # print("密码没有由3位以上字符组成")
    return 0

def passwd_repeat():
    global passwd
    for index, char in enumerate(passwd):
        if index < len(passwd)-2:
            str = passwd[index] + passwd[index + 1] + passwd[index + 2]
            passwd_model = passwd[index+3:]
            if str in passwd_model:
                # print("有长度超过或等于3的字串重复")
                return 0
    return 1

grade = 2
passwd = input("请输入密码:")
print(f"passwd是{passwd},长度为{len(passwd)}")
grade += passwd_length() + passwd_type() + passwd_repeat()
print(f"此密码的等级为{grade}")
if passwd_length() == 0:
    print("密码长度不符合要求，没有超过8位")
if passwd_type() == 0:
    print("密码没有由3位以上字符组成")
if passwd_repeat() == 0:
    print("有长度超过或等于3的字串重复")
